<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script>
      //XHR对象
      const getJSON = function (ur1) {
        const promise = new Promise(function (resolve, reject) {
          // 异步操作：网络请求代码

          const handler = function () {
            if (this.readyState !== 4) {
              return;
            } else {
              reject(new Error(this.statusText));
            }
          };
          const client = new XMLHttpRequest();
          client.open("GET", url);
          client.onreadystatechange = handler;
          client.responseType = "json";
          client.setRequestHeader("Accept", "application/json");
          client.send();~
        });
        return promise;
      };
      getJSON(
        "http://127.0.0.1:5500/JS%E9%AB%98%E7%BA%A7/45-%E5%AE%89%E8%A3%85babel.html"
      ).then(
        function (data) {
          console.log(data);
        },
        function (error) {
          console.log(error);
        }
      );
    </script>
  </head>
  <body></body>
</html>
